<template>
  <div class="components-container">
    <!-- <div class="header-form"> -->
       <!-- <div class="layui-inline" >
            <label class="layui-form-label">接尸日期</label>
            <div class="layui-inline" style="margin-top:-6px">
             <el-radio-group v-model="regDateValue" @change="getData">
              <el-radio-button  :label="now" class="radio">当日</el-radio-button>
              <el-radio-button  :label="future" class="radio">以后</el-radio-button>
              <el-radio-button  :label="all" class="radio">全部</el-radio-button>
             </el-radio-group>
            </div>
       </div> -->
        <!-- <div class="layui-inline">
          <label class="layui-form-label">业务编号</label>
            <div class="layui-inline">
              <el-input  v-model="RegbussnumLike" placeholder="请输入业务编号"></el-input>
            </div>
        </div> -->
          <!-- <el-button type="primary" @click="getData" :loading="this.$store.state.isloading">搜索</el-button>
          <el-button  @click="btnRepeat" >重置</el-button> -->
    <!-- </div> -->
    <div>
      <ul class="toolList">
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <!-- 附件管理新增 -->
    <el-dialog title="附件管理新增" :visible.sync="dialogTableVisible" :modal-append-to-body="false" width="60%">
        <div class="layui-inline">
            <label class="layui-form-label">附件选择</label>
            <div class="layui-input-inline backcolor">
                <el-select v-model="value" placeholder="请选择">
                    <el-option v-for="item in options" :key="item.Name" :label="item.Name" :value="item.Name"></el-option>
                </el-select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">必选附件</label>
            <div class="layui-input-inline backcolor">
                <el-select v-model="value5" multiple placeholder="请选择" @change="bxchange($event)">
                    <el-option v-for="item in bxoptions" :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue"></el-option>
                </el-select>
            </div>
        </div>
         <div class="layui-inline">
            <label class="layui-form-label">可选附件</label>
            <div class="layui-input-inline backcolor">
                <el-select v-model="value6" multiple placeholder="请选择" @change="kxchange($event)">
                    <el-option v-for="item in kxoptions" :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue"></el-option>
                </el-select>
            </div>
        </div>
        <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="dialogTableVisible = false">取 消</el-button>
            <el-button type="primary" @click="submit" :loading="this.$store.state.isloading">提 交</el-button>
        </span>
    </el-dialog> 
    <!-- 附件管理详情 -->
     <el-dialog title="附件管理详情" :visible.sync="dialogTableVisible1" :modal-append-to-body="false" width="40%">
        <el-tree :data="detaildata" :props="defaultProps" default-expand-all></el-tree>
        <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="dialogTableVisible1 = false">取 消</el-button>
        </span>
    </el-dialog>   

    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.longtext {
  width: 480px;
}
.longertext {
  width: 770px;
}
.sweet-btn {
  margin-top: 20px;
}
.radio {
  margin-top: 9px;
}
</style>
<script>
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { ORDER } from "@/const/orderConst.js";
import { manage } from "@/mixins/managePage.js";
export default {
  name: "fileManage",
  mixins: [manage],
  data() {
    return {
        // regDateValue: null,
        // RegbussnumLike: null,
        // now: null,
        // future: null,
        // all: null,
        order: null,
        value:null,
        value5: [],
        value6: [],
        dialogTableVisible:false,
        dialogTableVisible1:false,
        diechdData: [],
        alloptions: [],
        options: [],
        bxoptions: [],
        kxoptions: [],
        headList: [
            {ColumnAlign:"center",ColumnKey:"FTLNAME",ColumnName:"附件管理名称",ColumnOrder:"FTLNAME",ColumnWidth:500}
        ],
        detaildata: [],
        defaultProps: {
          children: 'children',
          label: 'label'
        }
    };
  },
  methods: {
    //获取火化登记数据
    getData() {
        let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().FileConfig.QueryFTL,
        res => {
            this.dataList = res.data.content.OutData;
        }
      );
    },
    // /Code/GetFileName
    //获取附件配置流程名称
    GetFileName(){
        let data = {};
        apiBase.DoService(
            data,
            apiBase.getApiAdress().FileConfig.QueryFileMain,
            res => {
                this.options = res.data.content;
            }
        )
    },
    //获取必选附件
    GetbxFileName(){
        let data = {};
        apiBase.DoService(
            data,
            apiBase.getApiAdress().Code.GetFileName,
            res => {
                this.alloptions = res.data.content;
                this.bxoptions = this.alloptions.slice();
                this.kxoptions = this.alloptions.slice();
            }
        )
    },
    bxchange(val){
        this.kxoptions = this.alloptions.slice();
        if(val.length != 0){
            for(var s = 0;s<val.length;s++){
                for(var i = 0; i<this.kxoptions.length;i++){
                    if(this.kxoptions[i].CodeValue == val[s]){
                        this.kxoptions.splice(i,1);
                    }
                }
            }
        }
    },
    kxchange(val){
        this.bxoptions = this.alloptions.slice();
        if(val.length != 0){
            for(var s = 0;s<val.length;s++){
                for(var i = 0; i<this.bxoptions.length;i++){
                    if(this.bxoptions[i].CodeValue == val[s]){
                        this.bxoptions.splice(i,1);
                    }
                }
            }
        }
    },
    //提交
    submit() {
        this.$store.state.isloading = true;
        switch(this.order){
            case '新增':
                this.addSubmit();
                break;
            case '修改':
                this.changeSubmit();
                break
            default:
        }
        
    },
    //新增提交
    addSubmit(){
        let data = {
            FTLNAME: this.value,
            ListMust:this.value5,
            ListNotMust:this.value6
        };
        apiBase.DoService(
            data,
            apiBase.getApiAdress().FileConfig.CreateFTL,
            res => {
               this.dialogTableVisible = false;
               this.getData();
            }
        )
    },
     //修改提交
    changeSubmit(){
        let data = {
            FTLID: this.currentRow.FTLID,
            ListMust:this.value5,
            ListNotMust:this.value6
        };
        apiBase.DoService(
            data,
            apiBase.getApiAdress().FileConfig.ModifyFTL,
            res => {
               this.dialogTableVisible = false;
            }
        )
    },
    //删除
    delete(){
         this.$confirm("确认是否删除该附件管理?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(callback => {
              let data = {
                FTLID: this.currentRow.FTLID
              };
              apiBase.DoService(
                data,
                apiBase.getApiAdress().FileConfig.DeleteFTL,
                res => {
                  this.getData();
                }
              );
            })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
    },

   
   //初始化下拉框数据
    initSelectData() {
        this.GetFileName();
        this.GetbxFileName();
    },
    btnShow(btn) {
      if(btn == '新增') return true;
      if(btn == '删除' && this.currentRow) return true;
      if(btn == '修改' && this.currentRow) return true;
      if(btn == '详情') return true;
    },
    //功能操作
    operate(order) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case "新增":
            this.initSelectData();
            this.dialogTableVisible = true;
            break;
        case "详情":
            this.dialogTableVisible1 = true;
            this.getDetail();
            break;
        case "修改":
            this.initSelectData();
            this.dialogTableVisible = true;
            this.getDetail();
            break;
        case "删除":
            this.delete();
            break;
        default:
      }
    },
   
    //查询条件重置
    btnRepeat() {
      Object.assign(this.$data.selectData, this.$options.data().selectData);
      this.initSeachdata();
    //   this.getData();
    },
    //数据重置
    dataRepeat() {
        this.value = null;
        this.value5 = [];
        this.value6 = [];
    },
    //详情
    getDetail(){
        let data = {
            FTLID: this.currentRow.FTLID
        };
        apiBase.DoService(
            data,
            apiBase.getApiAdress().FileConfig.DetailFTL,
            res => {
               let cardata = res.data.content;
                this.detaildata = [{
                    label:cardata.FTLNAME,
                    children: [{
                        label:"必选附件",
                        children: cardata.ListMust.map(item => ({
                            label:item
                        }))
                    },{
                        label:"可选附件",
                        children: cardata.ListNotMust.map(item => ({
                            label:item
                        }))
                    }]
                }];
                this.value = cardata.FTLNAME;
                this.value5 = cardata.ListMust;
                this.value6 = cardata.ListNotMust;
                this.bxchange(this.value5);
                this.kxchange(this.value6);
            }
        )
    },
    
  },
   created(){
       this.getData();
   },
  mounted() {
    // this.initSeachdata();
  },
  components: {
    dataTable,
  },
  watch: {

  }
};
</script>
